function extend_image(url,element){
    var setid = element.parentElement.getAttribute("photoset");
    if(setid){
        location.href = "photoset://"+setid;
        return;
    }
    var img=element.getElementsByTagName("IMG")[0];
    y=0;var desc=element.getAttribute("desc");
    var imgType = element.parentElement.className;

    var imgWidth = img.getAttribute("width").slice(0,-2);
    var imgHeight = img.getAttribute("height").slice(0,-2);
    while( element != null ) {
        y += element.offsetTop;
        element = element.offsetParent;
    }
    location.href="image:///"+y+"///"+ window.pageYOffset +"///"+url+"///"+desc+"///"+imgType+"///"+imgWidth+"///"+imgHeight;

}

function download_image(element){
    element.onclick = function() { return false; };
    element.innerHTML="<span> 下载中...</span>";
    location.href="downimage://" + element.parentElement.getAttribute("id").split('_')[1];
}

function play_video(url,element){
    location.href="video:///" + url;
}

function sub_topic(element){
    var className = element.className;
    if(className=='topic_plus no_tc'){
        element.className = 'topic_check no_tc';
        location.href = "topic://sub//"+element.getAttribute("id").split('_')[2];
    }else{
        element.className = 'topic_plus no_tc';
        location.href = "topic://unsub//"+element.getAttribute("id").split('_')[2];
    }
    return false;
}

function onLoad(){
    //处理推荐栏目
    var topics_section = document.getElementById('topics_section');
    if(topics_section){
        var myLinks = topics_section.getElementsByTagName('li');
        
        for(var i = 0; i < myLinks.length; i++){
            myLinks[i].addEventListener('touchstart', function(event){
                                            var touch = event.touches[0];
                                            //如果点击区域在最右边的60，就不走hover
                                            if(touch.pageX<320-60){
                                                this.id = "hover";
                                            }
                                        }, false);
            myLinks[i].addEventListener('touchend', function(){
                                        for(var j = 0; j < myLinks.length; j++){
                                            myLinks[j].id = ""
                                        }}, false);
        }
    }
    var relative_section = document.getElementById('relative_section');
    if(relative_section){
        var myLinks = relative_section.getElementsByTagName('li');
        
        for(var i = 0; i < myLinks.length; i++){
            myLinks[i].addEventListener('touchstart', function(event){
                                            this.id = "hover";
                                        }, false);
            myLinks[i].addEventListener('touchend', function(){
                                            for(var j = 0; j < myLinks.length; j++){
                                                myLinks[j].id = ""
                                        }}, false);
            myLinks[i].addEventListener('click', function(event){
                                            this.firstChild.className="no_tc read";
                                        }, false);
        }
    }
    setTimeout(function(){location.href = "show://" + document.body.scrollHeight;},100);
}
function reshow(){
    location.href = "reshow://" + document.body.scrollHeight;
}

window.addEventListener('load', onLoad, false);


